﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApiCoreDemo.Api.Filters;
using WebApiCoreDemo.Model;

namespace WebApiCoreDemo.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class FilterController : ControllerBase
    {
        public FilterController()
        {
            Console.WriteLine("执行ResourceFilterController()构造方法");
        }

        [HttpGet]
        [CustomActionFilter]
        [CustomResourceFilter]
        public string Get()
        {
            Console.WriteLine("执行ResourceFilterController.Get()方法");
            return "ResourceFilterController.Get()";
        }

        [HttpGet]
        [CustomResourceFilter]
        //[CustomActionFilter]//特性标记方式只支持无参构造方法
        //[TypeFilter(typeof(CustomActionFilterAttribute))]
        //[ServiceFilter(typeof(CustomActionFilterAttribute))]//必须先注册服务再使用
        //[CustomServiceFilter(typeof(CustomActionFilterAttribute))]//必须先注册服务再使用
        public Student GetInfo()
        {
            Console.WriteLine("执行ResourceFilterController.GetInfo()方法");
            return new Student() { Id = 12, Name = "ResourceFilterController.GetInfo()" };
        }
    }
}